package com.onetoall.yjt;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DELL on 2017/1/4.
 */

public class RecyActivity extends Activity {

    private LinearLayout linearLayout;
    private ListView rvOut;



    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_recy_activity);
        linearLayout = (LinearLayout) findViewById(R.id.ll_layout);
        rvOut = (ListView) findViewById(R.id.rv_outs);
        WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);

        Log.e("TAG",wm.getDefaultDisplay().getHeight()+"--->屏幕高度");
        final ViewTreeObserver vto = linearLayout.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Log.e("TAG","linear"+linearLayout.getHeight());
            }
        });
        List<String> datas = new ArrayList<>();
        boolean status[] = new boolean[7];
        for (int i=0;i<7;i++){
            datas.add("外层"+i);
            status[i] = false;
        }
        final LvOutAdapter lvOutAdapter = new LvOutAdapter(this,datas,status,rvOut,wm.getDefaultDisplay().getHeight()-getStatusBarHeight());
//        OutAdapter outAdapter = new OutAdapter(this,datas);
//        LinearLayoutManager manager = new LinearLayoutManager(this);
//        rvOut.setLayoutManager(manager);
        rvOut.setAdapter(lvOutAdapter);
        lvOutAdapter.setOnitemClickListener(new LvOutAdapter.OnItemClickListener() {
            @Override
            public void click(int position) {
                lvOutAdapter.notifyDataSetChanged();
                    rvOut.setSelection(position);
//                    rvOut.scrollTo(0,position*DesyUtil.dip2px(getApplicationContext(),65));

            }
        });
//        rvOut.setOnTouchListener(new View.OnTouchListener() {
//                                @Override
//                                public boolean onTouch(View v, MotionEvent event) {
//                                    switch (event.getAction()) {
//                    case MotionEvent.ACTION_MOVE:
//                        return true;
//                    default:
//                        break;
//                }
//                return true;
//                                }
//                            });

    }

    @Override
    protected void onResume() {
        super.onResume();

    }
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
            Log.e("TAG",result+"状态高度");
        }
        return result;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d("TAG","不停的在消费");
        Log.d("TAG",event.toString());
        Log.d("TAG",super.onTouchEvent(event)+"");
        return super.onTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.e("TAG","不停的在分发");
        Log.e("TAG",ev.toString());
        Log.e("TAG",super.dispatchTouchEvent(ev)+"");
        return super.dispatchTouchEvent(ev);
    }

}
